package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

/*
ID:		liluyan1
LANG:	JAVA
TASK:	checker
*/
public class checker {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("checker.in"));
		Solution res = new checker().solve(f);
		
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"checker.out")));
		for (String s : res.list) out.println(s);
		out.println(res.total);
		out.close();
		System.exit(0);
	}
	
	private int N;
	private Solution res;
	private int used = 0;
	
	private Solution solve(BufferedReader f) throws IOException {
		res = new Solution();
		N = read(f);
		int[] a = new int[N];
		dfs(0, a);
		
		// process for symmetry
		int L = res.list.size();
		if (L < 3) {
			for (int i=L, j=L-1; i<3; i++, j--) {
				res.list.add(reflect(res.list.get(j)));
			}
		}
		
		return res;
	}
	
	private String reflect(String s) {
		String[] t = s.split(" ");
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<N; i++) {
			int v = N + 1 - Integer.parseInt(t[i]);
			sb.append(i==0? v : " " + v);
		}
		return sb.toString();
	}
	
	private void dfs(int n, int[] a) {
		if (n == N) {
			res.total += (N%2==1 && a[0]==N/2)? 1 : 2;
			if (res.list.size() < 3) {
				StringBuilder sb = new StringBuilder();
				for (int i=0; i<N; i++) {
					sb.append(i==0? a[i]+1 : " " + (a[i]+1));
				}
				res.list.add(sb.toString());
			}
			return;
		}
		for (int i=0; i<N; i++) {
			// only calc to half in first row
			if (n == 0 && i>=(N+1)/2) break;
			
			if ((used & (1<<i)) > 0) continue; 
			a[n] = i;
			used |= 1<<i;
			if (test(a, n)) dfs(n+1, a);
			used &= ~(1<<i);
		}
	}
	
	private boolean test(int[] a, int n) {
		for (int i=n-1; i>=0 && a[n]>=n-i; i--) {
			if (a[i] == a[n]-n+i) return false;
		}
		
		for (int i=n-1; i>=0 && a[n]+n-i<N; i--) {
			if (a[i] == a[n]+n-i) return false;
		}
		
		return true;
	}
	
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	private class Solution {
		ArrayList<String> list = new ArrayList<String>();
		int total;
	}
}
